<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/headeradmin.php");
?>

<section>
<hgroup>
<h1>Bewoner-details beheren</h1>
</hgroup>

Klik <a href="patientdetailoverzichttoevoegen.php">hier</a> om een detail-veld van een bewoner toe te voegen.
                    <br><br>
                    
                    <?php
                    if (isset($_GET['start'])) { //Als we niet meer op de eerste pagina zitten is $_GET['start'] gekend en wordt deze waarde opgeslagen in $start
                        $start = $_GET['start'];
                    } else { //Als we nog op de eerste pagina zitten is $_GET['start'] niet gekend en wordt $start gelijkgesteld aan 0
                        $start = 0;
                    }

                    if (strlen($start) > 0 and !is_numeric($start)) { //controle op de waarde van $start
                        exit;
                    }
                    $eu = ($start - 0);
                    $limit = 20; //Het aantal records dat er per pagina getoond wordt
                    $thi = $eu + $limit;
                    $back = $eu - $limit;
                    $next = $eu + $limit;
                    $page_name = "patientdetailoverzicht.php?";
                    $query2 = "SELECT * from patientspec";
                    $result2 = mysql_query($query2);
                    $nume = mysql_num_rows($result2);
                    ?>

                    <table id="rounded-corner">
                        <thead>
                            <tr>
                                <th scope="col" class="rounded-company">Veld</th>
                                <th scope="col" class="rounded-q1">Commentaar</th>
                                <th scope="col" class="rounded-q2">Status</th>
                                <th scope="col" class="rounded-q3">Bewerken</th>
                                <th scope="col" class="rounded-q4">Deactiveren</th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr>
                                <td colspan="4" class="rounded-foot-left">
                                    <?php
                                    if ($limit < $nume) { //Het aanmaken van de links voor de verschillende pagina's
                                        if ($back >= 0) {
                                            echo "<a href=" . $page_name . "start=" . $back . ">Vorige</a>";
                                        }
                                        $i = 0;
                                        $l = 1;
                                        for ($i = 0; $i < $nume; $i = $i + $limit) {
                                            if ($i <> $eu) {
                                                echo " <a href=" . $page_name . "start=" . $i . ">$l</a> ";
                                            } else {
                                                echo "<span style=\"font-weight:bold;\">" . $l . "</span>";
                                            }
                                            $l = $l + 1;
                                        }
                                        if ($thi < $nume) {
                                            echo "<a href=" . $page_name . "start=" . $next . ">Volgende</a>";
                                        }
                                    }
                                    ?>
                                </td>
                                <td class="rounded-foot-right">&nbsp;</td>
                            </tr>
                        </tfoot>
                        <tbody>
                            <?php //Het ophalen van alle gegevens afhankelijk van welke pagina bekeken wordt
                            $query1 = "SELECT * from patientspec limit $eu, $limit";
                            $result1 = mysql_query($query1) or die(mysql_error());
                            while ($row1 = mysql_fetch_array($result1)) {

                                echo "<tr><td>" . $row1['PatientKey']."</td>";
                                echo "<td>" . $row1['Comment']."</td>";
                                
                                if ($row1['Activated'] == "T")
                                {
                                    echo "<td>Geactiveerd</td>";
                                }
                                else
                                {
                                    echo "<td>Gedeactiveerd</td>";
                                }
                                
                                
                                
                                
                                if (isset($_GET['start'])) {
                                    echo "<td><a href=\"patientdetailbewerken.php?id=" . $row1['Id'] . "&start=" . $_GET['start'] ."\" >Bewerken</a></td>";
                                    if ($row1['Activated'] == "T")
                                    {
                                        echo "<td><a href=\"patientdetaildeactiveren.php?id=" . $row1['Id'] . "&start=" . $_GET['start'] . "\" >Deactiveren</a></td>";
                                    }
                                    else
                                    {
                                        echo "<td><a href=\"patientdetailactiveren.php?id=" . $row1['Id'] . "&start=" . $_GET['start'] . "\" >Activeren</a></td>";
                                    }
                                } else {
                                    echo "<td><a href=\"patientdetailbewerken.php?id=" . $row1['Id'] . "\" >Bewerken</a></td>";
                                    if ($row1['Activated'] == "T")
                                    {
                                        echo "<td><a href=\"patientdetaildeactiveren.php?id=" . $row1['Id'] . "\" >Deactiveren</a></td>";
                                    }
                                    else
                                    {
                                        echo "<td><a href=\"patientdetailactiveren.php?id=" . $row1['Id'] . "\" >Activeren</a></td>";
                                    }
                                }
                            }
                            ?>
                        </tbody>
                    </table>

</section>

<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/footer.php");
?>